import os.path
import time
from datetime import datetime

from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Base:
    def __init__(self,driver:WebDriver,timeout:int=10):
        self.driver = driver
        self.wait=WebDriverWait(driver,timeout)

    def find(self,loc):
        return self.wait.until(EC.visibility_of_element_located(loc))

    def click(self,loc):
        self.find(loc).click()

    def send_keys(self,loc,info):
        self.find(loc).send_keys(info)

    def jietu(self):
        t = time.strftime('%Y%m%d%H%M%S', time.localtime())
        file=os.path.join('./img'+f'{t}.png')
        self.driver.save_screenshot(file)
        return file